﻿using System.Collections.Generic;
using System.Web;
using InfoSite.Data;


namespace InfoSite.Tools.Storage
{
	public class CacheHelper
	{
		public enum Keys
		{
			EditUser,
			GeoItems,
			AllUsers
		}

		public static SiteUserExtended EditUser { get; set; }

		private static object Get(Keys cacheKey)
		{
			return HttpRuntime.Cache[cacheKey.ToString()];
		}

		private static void Set(Keys cacheKey, object cacheValue)
		{
			HttpRuntime.Cache[cacheKey.ToString()] = cacheValue;
		}

		public static void SetEditUser(SiteUserExtended editUser)
		{
			Set(Keys.EditUser, editUser);
		}

		public static SiteUserExtended GetEditUser()
		{
			object oEditUser = Get(Keys.EditUser);
			if (oEditUser == null || oEditUser.GetType() != typeof(SiteUserExtended))
				return null;
			return (SiteUserExtended)oEditUser;
		}

		public static void SetAllUsers(IEnumerable<SiteUser> lAllUsers)
		{
			Set(Keys.AllUsers, lAllUsers);
		}

		public static IEnumerable<SiteUser> GetAllUsers()
		{
			object oListAllUsers = Get(Keys.AllUsers);
			if (oListAllUsers != null)
				return (IEnumerable<SiteUser>)oListAllUsers;
			return null;
		}
	}
}
